﻿@using CubicFWNet.Data.Models
@using CubicFWNet.Data.ViewModal
@model FinanceInvoice
@{
    var order = ViewBag.Order as Order;
    var customer = ViewBag.Customer as Customer;
    var operationName = ViewBag.OperationName;
    var operationTime = ViewBag.OperationTime;
    Layout = "~/Views/Shared/_InfoPage.cshtml";
}

<section class="content">
    <div class="box box-solid">
        <!-- /.box-header -->
        <div class="box-body">
            <div class="row">
                @if (Model != null && order != null && customer != null)
                {
                    <form class="form-horizontal" id="frmedit" action="@Url.Action("UpdateFinanceInvoice", "FinanceCost")" method="post">
                        <input type="hidden" id="OrderId" name="OrderId" value="@order.Id" />
                        <input type="hidden" id="Id" name="Id" value="@Model.Id" />
                        <input type="hidden" id="type" name="type" value="1" />
                        <div class="box-body">
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">订单号</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="OrderNumber" name="OrderNumber" value="@order.Number" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">客户名称</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="customerName" name="customerName" value="@customer.Name" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">发票号</label>
                                <div class="col-sm-9">
                                    @if (Model.Status == -1)
                                    {
                                        <input type="text" class="form-control" id="Number" name="Number" value="" readonly="readonly">
                                    }
                                    else
                                    {
                                        <input type="text" class="form-control" id="Number" name="Number" value="@Model.Number" readonly="readonly">
                                    }
                                </div>
                            </div>
                            <div class="form-group col-md-12" style="height: 1px;"></div>

                            <div id="json-content" class="col-md-12 ">
                                <input type="hidden" id="modalData" value="@Model.ProductData" readonly="readonly">
                                <table class="footable table table-stripped table-bordered table-hover" id="footable">
                                    <thead>
                                        <tr>
                                            <th data-sort-ignore="true">
                                                品名
                                            </th>
                                            <th data-hide="phone,table" data-sort-ignore="true">
                                                尺寸宽-mm
                                            </th>
                                            <th data-hide="phone,table" data-sort-ignore="true">
                                                尺寸长-mm
                                            </th>
                                            <th data-hide="phone,table" data-sort-ignore="true">
                                                基本单位
                                            </th>
                                            <th data-hide="phone,table" data-sort-ignore="true" class="col-md-2">
                                                数量
                                            </th>
                                            <th data-hide="phone,table" data-sort-ignore="true" class="col-md-2">
                                                价格
                                            </th>
                                            <th data-hide="phone,table" data-sort-ignore="true">
                                                增值税
                                            </th>
                                            <th data-hide="phone" data-sort-ignore="true" class="col-md-2">
                                                金额
                                            </th>
                                        </tr>
                                    </thead>
                                    <tbody id="data-content"></tbody>
                                </table>
                            </div>
                            <div class="form-group col-md-12" style="height: 1px;"></div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">备注</label>
                                <div class="col-sm-9">
                                    <textarea class="form-control" rows="3" placeholder="请输入 ..." name="FinanceInvoiceMemo" id="FinanceInvoiceMemo" readonly="readonly">@Model.FinanceInvoiceMemo</textarea>
                                </div>
                            </div>
                            <div class="form-group col-md-12" style="height: 1px;"></div>

                            <div class="form-group col-md-6">
                                <label for="operationName" class="col-sm-3 control-label">操作人</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="operationName" name="operationName" value="@operationName" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label for="operationTime" class="col-sm-3 control-label">日期</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="operationTime" name="operationTime" value="@operationTime" readonly="readonly">
                                </div>
                            </div>
                        </div>
                    </form>
                }
            </div>
        </div>
    </div>
</section>

<div id="loadingPage" style="display: none;">
    <div class="loading-shade"></div>
    <div class="loading-content" onclick="$.loading(false)">数据加载中，请稍后…</div>
</div>

@section Scripts{
    <script type="text/javascript">
        $(document).ready(function () {
            $("#frmedit").validate({
                submitHandler: function (form) {
                    var postData = $(form).formSerialize();
                    //postData.ProductData = getParam();
                    $.submitForm({
                        url: $(form).attr("action"),
                        param: postData,
                        success: function () {
                            //$.reload();
                            $.modalAlert("操作成功", "success");
                            if (type == 1) {
                                window.location.href = '@Url.Action("ReceivableQuery", "FinanceCost")';
                            }
                            if (type == 2) {
                                window.location.href = '@Url.Action("SendTicketQuery", "CustomerService")';
                            }
                        }
                    });
                }
            });


            var yy = document.getElementById("modalData").value;
            if (yy != "") {
                var data = JSON.parse(document.getElementById("modalData").value);
                var $content = $('#data-content');
                var html = "";
                for (var i = 0; i < data.length; i++) {
                    html += "<tr class='tr'>";
                    html += "<td>" + data[i].ProductName + "</td>";
                    html += "<td>" + data[i].ProductSizeWidth + "</td>";
                    html += "<td>" + data[i].ProductSizeWidth + "</td>";
                    html += "<td>" + data[i].ProductUnit + "</td>";
                    html += "<td>" + data[i].ProductAmount + "</td>";
                    html += "<td>" + data[i].ProductPrice + "</td>";
                    html += "<td>" + data[i].ProductTax + "</td>";
                    html += "<td>" + data[i].TotalMoney + "</td>";
                    html += "</tr>";
                }

                $content.append(html);
            }


            $('#footable').footable();
        });

        var type = 1;

        function formsubmit(t) {
            type = t;
            $("#type").val(t);
            $("#frmedit").submit();
        }

        $(".okeydown").on("keydown", function () {
            var k = event.keyCode;
            if ((k <= 57 && k >= 48) || (k <= 105 && k >= 96) || (k == 8) || (k == 110) || (k == 190)) {
                return true;
            } else {
                return false;
            }
        });

        $("#historyBack").click(function () {
            window.history.go(-1);  //返回上一页
            //window.history.back();  //返回上一页
        });
    </script>
}